package com.myidis.mapper;

import java.util.ArrayList;
import java.util.ArrayList;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.auxiliary.QuotaDataFinder;
import com.myidis.entity.QuotaData;

public interface QuotaDataMapper {
	@Select("SELECT * FROM quota_data")
    @Results({
    	@Result(property = "id", column = "id"),
    	@Result(property = "frequency", column = "frequency"),
        @Result(property = "time", column = "time"),
        @Result(property = "quota", column = "quota"),
        @Result(property = "dataItem", column = "dataitem"),
        @Result(property = "value", column = "value"),
        @Result(property = "unit", column = "unit")
    })
    ArrayList<QuotaData> all();
	
//	@Select("SELECT * FROM quota_data where quota = #{id} and time >= #{startTime} and time <= #{endTime}")
//    @Results({
//    	@Result(property = "id", column = "id"),
//    	@Result(property = "frequency", column = "frequency"),
//        @Result(property = "time", column = "time"),
//        @Result(property = "quota", column = "quota"),
//        @Result(property = "dataItem", column = "dataitem"),
//        @Result(property = "value", column = "value"),
//        @Result(property = "unit", column = "unit")
//    })
//    ArrayList<Double> getByQuota(QuotaDataFinder checkMapperReq);

    @Select("SELECT * FROM quota_data where quota = #{id} and time >= #{startTime} and time <= #{endTime}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "frequency", column = "frequency"),
            @Result(property = "time", column = "time"),
            @Result(property = "quota", column = "quota"),
            @Result(property = "dataItem", column = "dataitem"),
            @Result(property = "value", column = "value"),
            @Result(property = "unit", column = "unit")
    })
    ArrayList<QuotaData> getByQuota(String index, String startTime, String endTime);
	
	@Select("SELECT * FROM quota_data where quota = #{id} and time >= #{startTime} and time <= #{endTime}")
    @Results({
    	@Result(property = "id", column = "id"),
    	@Result(property = "frequency", column = "frequency"),
        @Result(property = "time", column = "time"),
        @Result(property = "quota", column = "quota"),
        @Result(property = "dataItem", column = "dataitem"),
        @Result(property = "value", column = "value"),
        @Result(property = "unit", column = "unit")
    })
    ArrayList<QuotaData> getByQuotaWithOther(QuotaDataFinder checkMapperReq);
    
    @Select("SELECT * FROM quota_data where quota = #{id} and time >= #{startTime} and time <= #{endTime} ORDER BY value")
    @Results({
    	@Result(property = "id", column = "id"),
    	@Result(property = "frequency", column = "frequency"),
        @Result(property = "time", column = "time"),
        @Result(property = "quota", column = "quota"),
        @Result(property = "dataItem", column = "dataitem"),
        @Result(property = "value", column = "value"),
        @Result(property = "unit", column = "unit")
    })
    ArrayList<QuotaData> getBySortQuota(QuotaDataFinder checkMapperReq);

    @Select("SELECT * FROM quota_data WHERE id = #{id}")
    @Results({
    	@Result(property = "id", column = "id"),
    	@Result(property = "frequency", column = "frequency"),
        @Result(property = "time", column = "time"),
        @Result(property = "quota", column = "quota"),
        @Result(property = "dataItem", column = "dataitem"),
        @Result(property = "value", column = "value"),
        @Result(property = "unit", column = "unit")
    })
     QuotaData getOne(int id);

    @Select("SELECT * FROM quota_data WHERE id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "frequency", column = "frequency"),
            @Result(property = "time", column = "time"),
            @Result(property = "quota", column = "quota"),
            @Result(property = "dataItem", column = "dataitem"),
            @Result(property = "value", column = "value"),
            @Result(property = "unit", column = "unit")
    })
    ArrayList<QuotaData> getByOne(int id);

    @Insert("INSERT INTO quota_data(frequency, time, quota, dataitem, value, unit) VALUES(#{frequency}, #{time}, #{quota}, #{dataItem}, #{value}, #{unit})")
    int insert(QuotaData quotaData);

    @Update("UPDATE quota_data SET id = #{id}, frequency = #{frequency}, time = #{time}, quota = #{quota}, dataitem = #{dataItem}, value = #{value}, unit = #{unit} WHERE id = #{id}")
    int update(QuotaData quotaData);

    @Delete("DELETE FROM quota_data WHERE id = #{id}")
    int delete(int id);


}
